/*
 * @Author: 侯志伟 
 * @Date: 2019-11-13 16:06:13 
 * @Last Modified by:   侯志伟 
 * @Last Modified time: 2019-11-13 16:06:13 
 */
import config from '../config/index'
/**
 * 设置cookie缓存  单位/天
 * @param {String} cookieName 
 * @param {String} cookieValue 
 * @param {int} cookieDates 
 */
export function saveCookie(cookieName, cookieValue, time) {
	var d = new Date();
	d.setDate(d.getDate() + (time || config.cookieExpires));
	document.cookie = cookieName + "=" + encodeURI(cookieValue) + ";expires=" + d.toGMTString();
}
/**
 * 获取cookie
 * @param {String} cookieName 
 */
export function getCookie(cookieName) {
	let _arr = document.cookie.split("; ").map(item => {
		var obj = obj || {};
		obj[item.split("=")[0]] = decodeURI(item.split("=")[1]);
		return obj;
	});
	for (var item in _arr) {
		if (_arr[item][cookieName]) {
			return _arr[item][cookieName];
		}
	}
	return null;
}
/**
 * 删除cookie
 * @param {String} cookieName 
 */
export function removeCookie(cookieName) {
	document.cookie = encodeURIComponent(cookieName) + "=; expires=" + new Date();
}